package com.nvt.core.dao.cb;

import java.util.Map;

import javax.sql.DataSource;

import oracle.jdbc.OracleTypes;

import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;

import com.nvt.core.dao.de.GenericResultSetExtractor;
import com.nvt.core.exception.NvtBusinessException;
import com.nvt.core.objectDomain.TxInParameter;

public class CallBackHandler extends StoredProcedure {

	public CallBackHandler(DataSource ds, String name) {
		super(ds, name);
	}

	// @SuppressWarnings("unchecked")
	public Map<String, Object> executeCallBack(Map<String, Object> txParameters)
			throws NvtBusinessException {

		TxInParameter[] inParameters = (TxInParameter[]) txParameters
				.get("inParams");
		Object[] values = new Object[inParameters.length];

		int counter = 0;
		for (TxInParameter inParameter : inParameters) {
			declareParameter(new SqlParameter(inParameter.getName(),
					inParameter.getSqlType()));
			values[counter++] = inParameter.getValue();
		}

		declareParameter(new SqlOutParameter("p_resultstring",
				OracleTypes.VARCHAR));
		// declareParameter(new SqlOutParameter("p_recordset",
		// OracleTypes.CURSOR,
		// new SpRowMapper()));
		declareParameter(new SqlOutParameter("p_recordset", OracleTypes.CURSOR,
				new GenericResultSetExtractor()));
		compile();

		Map<String, Object> result = execute(values);
		// ArrayList<TestVO> arrayList = (ArrayList<TestVO>) result
		// .get("p_recordset");
		return result;
	}
}
